package hot100;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/9/27 15:04
 */
public class lc148排序链表 {
    public static double calculateSquareRoot(double num) {
        if (num < 0) {
            throw new IllegalArgumentException("请输入一个非负数");
        }

        // 初始猜测值为num的一半
        double guess = num / 2;

        // 迭代计算直到精度满足要求
        while (Math.abs(guess * guess - num) > 0.0001) {
            guess = (guess + num / guess) / 2;
        }

        return guess;
    }

    public static void main(String[] args) {
        java.util.Scanner scanner = new java.util.Scanner(System.in);
        System.out.print("请输入一个数：");
        double number = scanner.nextDouble();
        scanner.close();

        double result = calculateSquareRoot(number);
        System.out.println("平方根为：" + result);
    }
}